/**
 * Author: 老洋
 * Date:  2021/3/31 18:55
 */
package com.yyy.config;


import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object logUser = request.getSession().getAttribute("loginUser");

        if(logUser != null){
            //登录成功
            return true;
        }else{
            //登录失败
            request.setAttribute("msg", "没有权限，不能访问");
            request.getRequestDispatcher("/index").forward(request, response);
            return false;
        }

    }
}